﻿layui.extend({
    unobtrusive:'lib/unobtrusive'
}).define(['form', 'index', 'unobtrusive','upload','layer'], function (exports) {
    var form = layui.form,
        index = layui.index,
        layer = layui.layer,
        upload = layui.upload;
    //获取模块中的页面名称
    var pageName = layui.cache.module.pageName;

    //登录页面
    if (pageName === 'login') {
        window.onLoginComplete = function (res) {
            index.handleCallbackResult(res,
                function () {
                    window.location.href = "/";
                }
            );
        }
    }
    //注册页面
    if (pageName==='register') {
        window.onRegisterComplete = function (res) {
            index.handleCallbackResult(res,
                function () {
                    window.location.href = "/Account/Login";
                });
        }
    }

    //用户设置页面
    if (pageName==='userSet') {
        window.onUserSetComplete = function (res) {
            index.handleCallbackResult(res,
                function () {
                    this.window.location.href = '/Account/UserSet';
                });
        }
    }
    //修改头像页面
    if (pageName === 'updateHeadImg') {
        upload.render({
            elem: '#btn_Upload',
            url: '/Account/UpdateUserHeadImg',
            done: function (rtnResult) {
                if (rtnResult.code !== 0) {
                    layer.alert(rtnResult.msg,
                        {
                            icon: 0,
                            title: '信息提示'
                        });
                } else {
                    window.location.href = '/Account/UpdateHeadImg'
                }
            }
        });
    }

    if (pageName==='updatePassword') {
        window.onUpdatePasswordComplete = function (res) {
            index.handleCallbackResult(res, function () {
                this.window.location.href = '/Account/SignOut';
            });
        }
    }
    ////用户信息修改页面
    //if (pageName === 'updateUserMsg') {
    //    $.post('/Admin/AccountManage/UpdateUserMsgInit',
    //       function (rtnResult) {
    //            if (rtnResult.code !== 0) {
    //                layer.alert(rtnResult.msg,
    //                    {
    //                        icon: 2,
    //                        title: '信息提示'
    //                    });
    //            } else {
                   
    //                var date = rtnResult.data;
    //                //初始化用户信息
    //                form.val('updateUser',
    //                    {
    //                        PhoneNumber: date.PhoneNumber,
    //                        Email: date.Email,
    //                        Sex: date.Sex.toString(),
    //                        RegisterTime: date.RegisterTime,
    //                        NickName: date.NickName
    //                    });
    //                if (date.HeadImgUrl) {
    //                    $('#img_HeadImg').attr('src', data.HeadImgUrl);
    //                }
    //            }
    //        });

    //    //修改用户头像
    //    upload.render({
    //        elem: '#btn_UpdateUserHeadImg',
    //        url: '/Admin/AccountManage/UpdateUserHeadImg',
    //        done: function (rtnResult) {
    //            $('#img_HeadImg').attr('src', rtnResult.data);
    //        }
    //    });

    //    //修改用户信息
    //    window.onUpdateUserComplete = function (res) {
    //        handleCallbackResult(res, function () {
    //            window.parent.location.href = "/Admin/Manage";
    //        });
    //    }
    //}

    ////Ajax数据处理
    //function handleCallbackResult(response, callback) {
    //    var rtnResult = response.responseJSON;
    //    if (rtnResult) {
    //        if (rtnResult.code !== 0) {
    //            layer.alert(rtnResult.msg,
    //                {
    //                    icon: 2,
    //                    title: '信息提示'
    //                });
    //        } else {
    //            callback && callback(rtnResult.data);
    //        }
    //    }
    //}

    ////请求开始的时候，开启加载状态
    //window.onRequestBegin = function () {
    //    layer.load(1,
    //        {
    //            shade: [0.1, '#000']
    //        }
    //    );
    //}

    ////请求加载完成后，关闭加载
    //window.onSuccess = function () {
    //    layer.closeAll();
    //}

    ////请求出现错误时，关闭加载层，提示系统错误
    //window.onRequestFailure = function () {
    //    layer.closeAll();
    //    layer.alert('服务器请求错误，请稍后重试',
    //        {
    //            icon: 2,
    //            title: '错误提示'
    //        });
    //}

    //window.onRequestComplete = function (res) {
    //    var rtnResult = res.responseJSON;
    //    if (rtnResult) {
    //        if (rtnResult.code !== 0) {
    //            layer.alert(rtnResult.msg,
    //                {
    //                    icon: 2,
    //                    title: '信息提示'
    //                });
    //        } else {
    //            this.window.location.href = "/Admin/Manage";
    //        }
    //    }
    //}
    exports('account', null);
})